package com.shujia.flink.sink

import org.apache.flink.streaming.api.functions.sink.{RichSinkFunction, SinkFunction}
import org.apache.flink.streaming.api.scala._

object Demo1SInk {
  def main(args: Array[String]): Unit = {

    val env: StreamExecutionEnvironment = StreamExecutionEnvironment.getExecutionEnvironment


    val ds: DataStream[String] = env.socketTextStream("master", 7777)


    //使用自定义的sink
    ds.addSink(new MySinkFunction)


    env.execute()


  }

}

/**
  * 自定义sink
  *
  * 实现SinkFunction  重写 invoke ，在invoke中将数据发送出去
  *
  *
  * RickSinkFunction  多了一个open和close方法
  *
  */


class MySinkFunction extends SinkFunction[String] {
  override def invoke(value: String, context: SinkFunction.Context[_]): Unit = {
    println("sink:" + value)
  }
}

